var prefix = jsctx + "/tenantReceive";

var tenantReceive = (function () {
    function init() {
        setTimeout(function () {//防止先于-读取缓存执行
            load();
        },10)
    };

    $('#exampleTable').on('load-success.bs.table', function (e, data) {
        if (data.total && !data.rows.length) {
            $('#exampleTable').bootstrapTable('selectPage').bootstrapTable('refresh');
        }
    });
    var h = $(window).height() - 80;
    function load() {

        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get',
                    url: prefix + "/listPageTenantReceive",

                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: false,
                    dataType: "json",
                    pagination: true,
                    singleSelect: false,
                    pageSize: 10,
                    pageList: [10,20,30],
                    pageNumber: 1,
                    sidePagination: "server",
                    cache:false,
                    paginationShowPageGo: true,
                    height: h,
                    queryParams: function (params) {
                        return {
                            limit: params.limit,
                            offset: (params.offset / params.limit) + 1,
                            status: $("#status").val().trim(),
                            endTime: $("#endTime").val().trim(),
                            startTime: $("#startTime").val().trim(),
                            title: $("#title").val().trim()

                        };
                    },
                    columns: [


                        {
                            title: '#', field: '',width:'40',align: 'center',
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        },
                        {field: 'title', title: '消息标题', align: 'center', width: '270'},
                        {field: 'content', title: '消息内容', width:'600',align: 'center'},
                        {field: 'createdTime', title: '发出时间', width:'170',align: 'center'},

                        {
                            field: 'status', title: '未读/已读', width:'80',align: 'center',
                            formatter: function (value, row, index) {
                                if (row.status == '0') {
                                    return '<span class="label label-success">未读</span>';
                                } else if (row.status == '1') {
                                    return '<span class="label label-warning">已读</span>';
                                }
                            }
                        },

                        {field: 'showPlaceType', title: '置顶', width:'60',align: 'center',
                            formatter: function (value, row, index) {
                                // if (row.isRead == '0') {
                                //     return '<span class="label label-success">未读</span>';
                                // } else if (row.isRead == '1') {
                                //     return '<span class="label label-warning">已读</span>';
                                // }
                                if(row.showPlaceType == '1'){
                                    return '<img src="'+jsctx+'/statics/img/star2.png">'
                                }
                            }
                        },

                        {
                            title: '操作',
                            field: 'orderId',
                            width:'80',align: 'center',
                            formatter: function (value, row, index) {
                                var a = '<a class="btn btn-success btn-sm ' + has_edit + '" href="#" title="桩列表" onclick="tenantReceive.chatRecord(\''
                                    + row.receiveId
                                    + '\')">详情</a> ';

                                return a;
                            }
                        }
                    ]
                });
    }

    function reLoad() {
        $('#exampleTable').bootstrapTable('refresh');
    }

    function goBack() {
        location.href = prefix + "/index";
    }

    function chatRecord(receiveId) {
        location.href = prefix + "/detailTenantReceive/" + receiveId;
    }

    return {
        init: init,
        goBack: goBack,
        reLoad: reLoad,
        chatRecord: chatRecord,
        load:load
    };
})();
